const { findBannerService, updateBannerService } = require('../services/bannerService');
const AppError = require('../utils/AppError');
const { toi } = require('../utils/tools');

class BannerController {
	async findBanners(req, res, next) {
		await toi(findBannerService(), res, next);
	}

	async updateBanners(req, res, next) {
		const schema = req.joi.array().items({
			midImg: req.joi.string().required(),
			bigImg: req.joi.string().required(),
			title: req.joi.string().required(),
			description: req.joi.string().required()
		});
		const { error: failed } = schema.validate(req.body || []);
		if (failed) return next(new AppError(failed, 400));

		await toi(updateBannerService(req.body), res, next);
	}
}

module.exports = new BannerController();
